﻿

using System;
using System.Collections.Generic;
using System.Data;
using BusinessObjects.BussinessDictionary;
using DataObjects.Shared;
using DataObjects.StandartInterfaces.Dictionary;

namespace DataObjects.ADO.SqlServer.Dictionary
{

    /// <summary>
    /// 
    /// </summary>
    public class SqlServerEmployTest : IEmployTest
    {
        /// <summary>
        /// Takes the specified employ test.
        /// </summary>
        /// <param name="employTest">The employ test.</param>
        /// <returns></returns>
        private static object[] Take(EmployTest employTest)
        {
            return new object[]  
            {
                "@EmployID", employTest.EmployId,
                "@Name", employTest.Name,
                "@Salary", employTest.Salary,
                "@DepartmentID", employTest.DepartmentId
            };
        }
        /// <summary>
        /// The make
        /// </summary>
        private static readonly Func<IDataReader, EmployTest> Make = reader =>
          new EmployTest
          {
              EmployId = reader["EmployID"].AsId(),
              Name = reader["Name"].AsString(),
              Salary = reader["Salary"].AsDecimal(),
              DepartmentId = reader["DepartmentID"].AsInt()
          };

        /// <summary>
        /// Gets the paged.
        /// </summary>
        /// <param name="unitId">The unit identifier.</param>
        /// <param name="currentPage">The current page.</param>
        /// <returns></returns>
        /// <exception cref="System.NotImplementedException"></exception>
        public List<EmployTest> GetPaged(int unitId, int currentPage)
        {
            const string sql = @"uspGetPaged_EmployTest";
            object[] parms = { "@WhereClause", null, "@OrderBy", null, "@PageIndex", currentPage - 1, "@UnitID", unitId };
            return Db.ReadList(sql, CommandType.StoredProcedure, Make, parms);
        }

        /// <summary>
        /// </summary>
        /// <param name="unitId"></param>
        /// <returns></returns>
        /// <exception cref="System.NotImplementedException"></exception>
        public int GetPageSize(int unitId)
        {
            const string sql = @"uspGetPageSize_EmployTest";
            object[] parms = { "@WhereClause", null, "@UnitID", unitId };
            return Db.GetCount(sql, CommandType.StoredProcedure, parms);
        }      
       

        /// <summary>
        /// Inserts the employTest.
        /// </summary>
        /// <param name="employTest">The employTest.</param>
        /// <returns></returns>
        public string InsertEmployTest(EmployTest employTest)
        {
            const string sql = "uspInsert_EmployTest";
            return Db.Insert(sql, CommandType.StoredProcedure, Take(employTest));
        }

        /// <summary>
        /// Updates the employTest.
        /// </summary>
        /// <param name="employTest">The employTest.</param>
        /// <returns></returns>
        public string UpdateEmployTest(EmployTest employTest)
        {
            const string sql = "uspUpdate_EmployTest";
            return Db.Update(sql, CommandType.StoredProcedure, Take(employTest));
        }

        /// <summary>
        /// Deletes the employTest.
        /// </summary>
        /// <param name="employTest">The employTest.</param>
        /// <returns></returns>
        public string DeleteEmployTest(EmployTest employTest)
        {
            const string sql = @"uspDelete_EmployTest";
            object[] parms = { "@EmployID", employTest.EmployId };
            return Db.Delete(sql, CommandType.StoredProcedure, parms);
        }





        EmployTest IEmployTest.GetEmployTest(int employTestId)
        {
            const string sql = @"uspGet_EmployTest_ByID";
            object[] parms = { "@EmployID", employTestId };
            return Db.Read(sql, CommandType.StoredProcedure,Make, parms);
        }
    }
}
